<?php
/**
 * Name: IndexController.php.
 * Author: JiaMeng <666@majiameng.com>
 * Date: 2018/4/16 14:12
 * Description: IndexController.php.
 */
namespace App\Http\Controllers\Web\Payment;

use App\Http\Controllers\BaseController;
use App\Services\Payment\PayNotifyService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class NotifyController extends BaseController
{
    /**
     * @param PayNotifyService $service
     * @param Request $request
     */
    public function __construct(PayNotifyService $service,Request $request){
        parent::__construct($request);
        $this->service = $service;
    }

    /**
     * 支付回调处理
     * @param $method
     * @param $params
     * @return mixed
     */
    public function __call($method, $params)
    {
        $app_id = $params[0]??'';

        //记录支付回调原数据日志
        if($method == 'wechat'){
            $content = "method {$method} callback ,appid:{$app_id}, header:".json_encode($this->request->header()).",file_content:".file_get_contents('php://input', 'r');
        }else{
            $content = "method {$method} callback ,appid:{$app_id}, header:".json_encode($_REQUEST).",file_content:".file_get_contents('php://input', 'r');
        }
        Log::channel('paylog')->info($content);

        $this->service->app_id = $app_id;
        $this->service->getCompany();
        return $this->service->$method();
    }

}
